Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sound effects to the game #6

Merged
merged 4 commits into from
Dec 10, 2022
Merged

Add sound effects to the game #6

merged 4 commits into from
Dec 10, 2022

Conversation

mrnakumar
Copy link
Contributor

@mrnakumar mrnakumar commented Dec 8, 2022

Play sound when:

  • snake eats an apple
  • game over

To play without sound, command line flag --silent should be passed.

Narendra Kumar added 2 commits December 9, 2022 00:09
A commandline argument is reuiqred to give base path
of assets directory. This directory must have file
'gameOver.mp3'.
A commandline argument is reuiqred to give base path
of assets directory. This directory must have file
'hiss.mp3'.
@mrnakumar
Copy link
Contributor Author

@liweiyi88

@liweiyi88
Copy link
Owner

liweiyi88 commented Dec 10, 2022

@mrnakumar thanks for your PR, it looks cool!
I would make 2 suggestions based on the PR.

  1. Let's use the standard package embed to load the static file at compile time. Thus we do not need to pass the path argument to load the file at runtime. What you can do is basically create a file in the assets folder and export a var like the below snippet (assets/embed.go)
package assets

import "embed"

//go:embed *
var Assets embed.FS

Then use assets.Assets as the normal file to read the mp3. e.g.

f, err := assets.Assets.Open(filename)
	if err != nil {
		return nil, beep.Format{}, err
	}
  1. It would be better to add a command option (--silent) to mute the background music. Afterall, there are some time when people want to play the game without any background sounds.

Please let me know your thoughts.

Narendra Kumar added 2 commits December 10, 2022 21:42
The use of go:embed directive is to avoid having to pass assets
directory path via command line.
The flag --silent can be passed to start in mute..
@mrnakumar
Copy link
Contributor Author

@liweiyi88 thanks for comments. I have made changes accordingly. Please let me know if this is okay.

@liweiyi88
Copy link
Owner

@mrnakumar Well done 🎉

@liweiyi88 liweiyi88 merged commit 0cdda35 into liweiyi88:main Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants